package core.testes.lexical;

import java.io.EOFException;
import java.io.FileReader;
import java.io.IOException;

import junit.framework.TestCase;
import core.LexicalToken;
import core.error.ErrorHandler;
import core.lexical.LexicalAnalyser;

public class LexicalAnalyserTest extends TestCase {
	LexicalAnalyser a;

	public void setUp() throws Exception {
		a = new LexicalAnalyser(new FileReader("examples\\lexicalAnalyserTest.ford"), new ErrorHandler() );
	}

	public void tearDown() throws Exception {
	}
	
	public void testGetNextLexicalToken() throws EOFException, IOException {
		
//		line 1
		LexicalToken token = a.nextToken();
		assertEquals("int", token.getToken());
		assertEquals("TYPE", token.getCode().toString());
		
		token = a.nextToken();
		assertEquals("a", token.getToken());
		assertEquals("IDENTIFIER", token.getCode().toString());

		token = a.nextToken();
		assertEquals(";", token.getToken());
		assertEquals("END_OF_COMMAND", token.getCode().toString());
		
		//line 2
		token = a.nextToken();
		assertEquals("boolean", token.getToken());
		assertEquals("TYPE", token.getCode().toString());

		token = a.nextToken();
		assertEquals("b", token.getToken());
		assertEquals("IDENTIFIER", token.getCode().toString());

		token = a.nextToken();
		assertEquals(";", token.getToken());
		assertEquals("END_OF_COMMAND", token.getCode().toString());

		//line 3
		token = a.nextToken();
		assertEquals("string", token.getToken());
		assertEquals("TYPE", token.getCode().toString());

		token = a.nextToken();
		assertEquals("c", token.getToken());
		assertEquals("IDENTIFIER", token.getCode().toString());

		token = a.nextToken();
		assertEquals(";", token.getToken());
		assertEquals("END_OF_COMMAND", token.getCode().toString());
		
		//line 4
		token = a.nextToken();
		assertEquals("arrayof", token.getToken());
		assertEquals("TYPE", token.getCode().toString());
		
		token = a.nextToken();
		assertEquals("int", token.getToken().toString());
		assertEquals("TYPE", token.getCode().toString());

		token = a.nextToken();
		assertEquals("d", token.getToken());
		assertEquals("IDENTIFIER", token.getCode().toString());

		token = a.nextToken();
		assertEquals("[", token.getToken());
		assertEquals("OPENING_BRACKET", token.getCode().toString());

		token = a.nextToken();
		assertEquals("10", token.getToken());
		assertEquals("NUMBER", token.getCode().toString());

		token = a.nextToken();
		assertEquals("]", token.getToken());
		assertEquals("CLOSING_BRACKET", token.getCode().toString());

		token = a.nextToken();
		assertEquals(";", token.getToken());
		assertEquals("END_OF_COMMAND", token.getCode().toString());
		
		//line 5
		token = a.nextToken();
		assertEquals("arrayof", token.getToken());
		assertEquals("TYPE", token.getCode().toString());
		
		token = a.nextToken();
		assertEquals("string", token.getToken());
		assertEquals("TYPE", token.getCode().toString());

		token = a.nextToken();
		assertEquals("e", token.getToken());
		assertEquals("IDENTIFIER", token.getCode().toString());

		token = a.nextToken();
		assertEquals("[", token.getToken());
		assertEquals("OPENING_BRACKET", token.getCode().toString());

		token = a.nextToken();
		assertEquals("10", token.getToken());
		assertEquals("NUMBER", token.getCode().toString());

		token = a.nextToken();
		assertEquals("]", token.getToken());
		assertEquals("CLOSING_BRACKET", token.getCode().toString());

		token = a.nextToken();
		assertEquals(";", token.getToken());
		assertEquals("END_OF_COMMAND", token.getCode().toString());

		//line 6
		token = a.nextToken();
		assertEquals("int", token.getToken());
		assertEquals("TYPE", token.getCode().toString());

		token = a.nextToken();
		assertEquals("soma", token.getToken());
		assertEquals("IDENTIFIER", token.getCode().toString());

		token = a.nextToken();
		assertEquals(";", token.getToken());
		assertEquals("END_OF_COMMAND", token.getCode().toString());

		//line 8
		token = a.nextToken();
		assertEquals("boolean", token.getToken());
		assertEquals("TYPE", token.getCode().toString());

		token = a.nextToken();
		assertEquals("finish", token.getToken());
		assertEquals("IDENTIFIER", token.getCode().toString());

		token = a.nextToken();
		assertEquals(";", token.getToken());
		assertEquals("END_OF_COMMAND", token.getCode().toString());
		
		token = a.nextToken();
		assertEquals("boolean", token.getToken());
		assertEquals("TYPE", token.getCode().toString());
		
		token = a.nextToken();
		assertEquals("tmp", token.getToken());
		assertEquals("IDENTIFIER", token.getCode().toString());
		
		//line 9
		token = a.nextToken();
		assertEquals(";", token.getToken());
		assertEquals("END_OF_COMMAND", token.getCode().toString());
		
		//line 10
		token = a.nextToken();
		assertEquals("main", token.getToken());
		assertEquals("IDENTIFIER", token.getCode().toString());
		
		token = a.nextToken();
		assertEquals("{", token.getToken());
		assertEquals("OPENING_BRACE", token.getCode().toString());

		token = a.nextToken();
		assertEquals("}", token.getToken());
		assertEquals("CLOSING_BRACE", token.getCode().toString());


	}
}
